package com.teradata.cxf.server.listmap;

import com.teradata.cxf.entities.DataResult;
import com.teradata.cxf.entities.User;

import javax.jws.WebService;
import java.util.*;

/**
 * @author lyndon
 * @date 2018/7/30T16:45
 */
@WebService(serviceName = "ListMapService" //服务名
        , targetNamespace = "http://entities.cxf.teradata.com" //报名倒叙，并且和接口定义保持一致
        , endpointInterface = "com.teradata.cxf.server.listmap.ListMapService") //SEI接口名
public class ListMapServiceImpl implements ListMapService {

    @Override
    public List<Map> getListMap1() {
        List<Map> listMap = new ArrayList<Map>();
        for (int i = 0; i < 5; i++) {
            Map map = new HashMap<String, User>();
            for (int j = 0; j < 5; j++) {
                /*User user = new User(new Random().nextInt(), "user" + j, "男", "user" + j + "@teradata.com",
                        Arrays.asList(
                                new Car(new Random().nextInt(), "奔驰", 740198.00),
                                new Car(new Random().nextInt(), "宝马", 811199.00)
                        ));*/
                User user = new User(new Random().nextInt(), "user" + i + j);
                map.put("key" + i + j, user);
            }
            listMap.add(map);
        }
        return listMap;
    }

    @Override
    public List<Map> getListMap() {
        List<Map> listMap = new ArrayList<Map>();
        for (int i = 0; i < 5; i++) {
            Map map = new HashMap();
            for (int j = 0; j < 5; j++) {
                map.put("key" + i + j, "value" + i + j);
            }
            listMap.add(map);
        }
        return listMap;
    }

    @Override
    public DataResult getMap() {
        DataResult result = new DataResult();
        List<User> userList = new ArrayList<User>();
        Map<String, User> userMap = new HashMap<String, User>();

        for (int i = 0; i < 5; i++) {
            /*User user = new User(new Random().nextInt(), "user" + i, "男", "user" + i + "@teradata.com",
                    Arrays.asList(
                            new Car(new Random().nextInt(), "奔驰", 740198.00),
                            new Car(new Random().nextInt(), "宝马", 811199.00)
                    ));*/
            User user = new User(new Random().nextInt(), "user" + i);
            userList.add(user);
            userMap.put("key" + i, user);
        }
        result.setUserList(userList);
        result.setUserMap(userMap);
        return result;
    }


    @Override
    public String getName(String param) {
        return param;
    }
}
